package com.example.demo.controller;

import com.example.demo.bean.Teams;
import com.example.demo.service.TeamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teams")
public class TeamsController {
    @Autowired
    TeamsService service;

    @RequestMapping("/list")
    public Map getAll() {
        List<Teams> all = service.getAll();
        Map map = new HashMap();
        if (all != null) {
            map.put("success", true);
            map.put("massage", "请求成功");
            map.put("data", all);
        } else {
            map.put("success", false);
            map.put("massage", "请求失败");
            map.put("data", null);
        }
        return map;
    }

    @RequestMapping("/findOne")
    public Map getAll(@RequestBody Teams teams) {
        Teams teams1 = service.findById(teams.getId());
        Map map = new HashMap();
        if (teams1 != null) {
            map.put("success", true);
            map.put("massage", "请求成功");
            map.put("data", teams1);
        } else {
            map.put("success", false);
            map.put("massage", "请求失败");
            map.put("data", null);
        }
        return map;
    }
}
